/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.click.app.model;

/**
 *
 * @author arnold
 */
import com.click.app.Functions;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 *
 * @author ariel
 */
@Entity
@Table(name = "balance_laundries")
public class BalanceLaundry extends BaseObject implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long id;
    private Date dateBalance;
    private Double amountWon;
    private Double amountPaid;
    private Double balance;
    private LaundryRequest laundryRequest;
    private PeriodPaymentLaundry periodPaymentLaundry;
    private PaymentsLaundry paymentsLaundry;
    private String observation;
    private Integer typeBalance; // 1 normal increment ; 2 increment discount ; 3 normal payment ; 4 fail payment

    public BalanceLaundry(){}

    public BalanceLaundry(Double balance){
        this.balance = balance;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name="id_balance_laundry", unique=true, nullable=false)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Temporal(TemporalType.DATE)
    public Date getDateBalance() {
        return dateBalance;
    }

    public void setDateBalance(Date date) {
        this.dateBalance = date;
    }

    @Column(name = "observation", length = 255)
    public String getObservation() {
        return observation;
    }

    public void setObservation(String observation) {
        this.observation = observation;
    }

    @Column(name="type_balance")
    public Integer getTypeBalance() {
        return typeBalance;
    }

    public void setTypeBalance(Integer typeBalance) {
        this.typeBalance = typeBalance;
    }

    @Column(name = "amount_won")
    public Double getAmountWon() {
        return Functions.getDouble3Decimal(amountWon);
    }

    public void setAmountWon(Double amountWon) {
        this.amountWon = Functions.getDouble3Decimal(amountWon);
    }

    @Column(name = "amount_paid")
    public Double getAmountPaid() {
        return Functions.getDouble3Decimal(amountPaid);
    }

    public void setAmountPaid(Double amountPaid) {
        this.amountPaid = Functions.getDouble3Decimal(amountPaid);
    }

    public Double getBalance() {
        return Functions.getDouble3Decimal(balance);
    }

    public void setBalance(Double balance) {
        this.balance = Functions.getDouble3Decimal(balance);
    }

    @JoinColumn(name = "id_payments_laundry", referencedColumnName = "id_payments_laundry")
    @OneToOne
    public PaymentsLaundry getPaymentsLaundry() {
        return paymentsLaundry;
    }

    public void setPaymentsLaundry(PaymentsLaundry paymentsLaundry) {
        this.paymentsLaundry = paymentsLaundry;
    }

    @JoinColumn(name = "id_laundry_request", referencedColumnName = "id_laundry_request")
    @OneToOne
    public LaundryRequest getLaundryRequest() {
        return laundryRequest;
    }

    public void setLaundryRequest(LaundryRequest laundryRequest) {
        this.laundryRequest = laundryRequest;
    }


    @JoinColumn(name = "id_period_payment_laundry", nullable = false)
    @ManyToOne(fetch = FetchType.LAZY)
    public PeriodPaymentLaundry getPeriodPaymentLaundry() {
        return periodPaymentLaundry;
    }

    public void setPeriodPaymentLaundry(PeriodPaymentLaundry periodPaymentLaundry) {
        this.periodPaymentLaundry = periodPaymentLaundry;
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append(this.getId())
           .append(this.dateBalance).append(this.amountWon).append(this.amountPaid)
           .append(this.balance).append(this.laundryRequest).append(this.periodPaymentLaundry)
           .append(this.paymentsLaundry).append(this.observation).append(this.typeBalance)
           .toString();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final BalanceLaundry other = (BalanceLaundry) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        if (this.dateBalance != other.dateBalance && (this.dateBalance == null || !this.dateBalance.equals(other.dateBalance))) {
            return false;
        }
        if (this.amountWon != other.amountWon && (this.amountWon == null || !this.amountWon.equals(other.amountWon))) {
            return false;
        }
        if (this.amountPaid != other.amountPaid && (this.amountPaid == null || !this.amountPaid.equals(other.amountPaid))) {
            return false;
        }
        if (this.balance != other.balance && (this.balance == null || !this.balance.equals(other.balance))) {
            return false;
        }
        if (this.laundryRequest != other.laundryRequest && (this.laundryRequest == null || !this.laundryRequest.equals(other.laundryRequest))) {
            return false;
        }
        if (this.periodPaymentLaundry != other.periodPaymentLaundry && (this.periodPaymentLaundry == null || !this.periodPaymentLaundry.equals(other.periodPaymentLaundry))) {
            return false;
        }
        if ((this.observation == null) ? (other.observation != null) : !this.observation.equals(other.observation)) {
            return false;
        }
        if (this.typeBalance != other.typeBalance && (this.typeBalance == null || !this.typeBalance.equals(other.typeBalance))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + (this.id != null ? this.id.hashCode() : 0);
        hash = 23 * hash + (this.dateBalance != null ? this.dateBalance.hashCode() : 0);
        hash = 23 * hash + (this.amountWon != null ? this.amountWon.hashCode() : 0);
        hash = 23 * hash + (this.amountPaid != null ? this.amountPaid.hashCode() : 0);
        hash = 23 * hash + (this.balance != null ? this.balance.hashCode() : 0);
        hash = 23 * hash + (this.laundryRequest != null ? this.laundryRequest.hashCode() : 0);
        hash = 23 * hash + (this.periodPaymentLaundry != null ? this.periodPaymentLaundry.hashCode() : 0);
        hash = 23 * hash + (this.observation != null ? this.observation.hashCode() : 0);
        hash = 23 * hash + (this.typeBalance != null ? this.typeBalance.hashCode() : 0);
        return hash;
    }
    
}
